#include <bits/stdc++.h>
// 2025/06/16
// tag:
// Author: Forever
using namespace std;
using int64 = int64_t;

#define int long long
const int N = 100001;
int n, m, w[N], sum[N], s[N];

double average(int l, int r)
{
    return (sum[r] - sum[l - 1]) * 1.0 / (r - l + 1);
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> w[i], sum[i] = sum[i - 1] + w[i], s[i] = s[i - 1] + w[i] * w[i];
    for (int i = 1; i <= m; i++) {
        int l, r;
        cin >> l >> r;
        double A = average(l, r);
        cout << fixed << setprecision(3) << (s[r] - s[l - 1] - A * (sum[r] - sum[l - 1]) * 2) / (r - l + 1) + A * A << endl;
    }
    return 0;
}